﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMCgui
{
    class LogUserControl : TransitionUserControl
    {
        private System.Windows.Forms.RichTextBox rtbLog;

        public LogUserControl()
        {
            InitializeComponent();
            rtbLog.Text = GetText();
            Dock = DockStyle.Fill;
        }

        private string GetText()
        {
            if (File.Exists(PMC.Properties.Settings.Default.LogFile))
            {
                try
                {
                    using (var fs = new FileStream(PMC.Properties.Settings.Default.LogFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (var reader = new StreamReader(fs))
                        {
                            var buffer = new char[150000];
                            reader.Read(buffer, 0, buffer.Length);
                            return new string(buffer);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show(Language.Instance.ErrorReadingLog);
                }
            }
            return string.Empty;
        }
    
        private void InitializeComponent()
        {
            this.rtbLog = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // rtbLog
            // 
            this.rtbLog.Dock = System.Windows.Forms.DockStyle.Fill;
            this.rtbLog.Location = new System.Drawing.Point(0, 0);
            this.rtbLog.Name = "rtbLog";
            this.rtbLog.Size = new System.Drawing.Size(293, 332);
            this.rtbLog.TabIndex = 0;
            this.rtbLog.Text = "";
            // 
            // LogUserControl
            // 
            this.Controls.Add(this.rtbLog);
            this.Name = "LogUserControl";
            this.Size = new System.Drawing.Size(293, 332);
            this.ResumeLayout(false);

        }
    }
}
